#include "makedata.h"
#include "string.h"
/*
R:红灯数据 0~255
G:绿灯数据 0~255
B:蓝灯数据 0~255
Msp:电机数据 -100~100
"R:255,G:100,B:0,Msp:20\r\n"

&&(*p!='\r'&&*(p+1)!='\n')

(*p-'0')：转换为对应数值，如：'5'转换为5
*/

TYPE_DATA MotorStringMake(unsigned char *buf)
{
    char *p;
    TYPE_DATA value={0,0,0,0,0};
    #if 0
	
	
	int8_t flag=1;
	
	//解析R: 红灯数据
	p=strstr((const char *)buf,"R:");   // { R:123,G:12,}
	p=p+2;
	while( *p!=',')
	{
		value.red=value.red*10+(*p-'0'); 
		p++;
	} 
		
	//解析G: 绿灯数据
	p=strstr((const char *)buf,"G:");
	p=p+2;
	while( *p!=',')
	{
		value.green=value.green*10+(*p-'0'); 
		p++;
	}
		
	//解析B: 蓝灯数据
	p=strstr((const char *)buf,"B:");
	p=p+2;
	while( *p!='"')
	{
		value.blue=value.blue*10+(*p-'0'); 
		p++;
	}
		
	//Msp:电机数据
	p=strstr((const char *)buf,"\"MotorSpeed\"");
	p=p+13;
	if(*p=='-')//负数
	{
		flag=-1;
		p=p+1; 	
	}
	while( *p!=','&&*p!='}') //673  54
	{
			value.speed=value.speed*10+(*p-'0'); 
			p++;
	} 
	value.speed=flag*value.speed;
	
	
    #endif
    
    p=strstr((const char *)buf,"\"AlarmSwitch\"");
    p=p+14;
    
    value.LED = *p - '0';//Asiic
    
    return value;
} 
